package com.chiangleoi.appointment.utils;

import java.util.Base64;

/**
 * 江体加密类
 *
 * @author ChiangLeoi
 */
public class SvCipherUtils {

    public static String getSvCiphertext(String ss) {
        String suiji = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        String token1 = String.valueOf(suiji.charAt((int) (Math.random() * suiji.length())));
        String token2 = String.valueOf(suiji.charAt((int) (Math.random() * suiji.length())));
        System.out.println(token1 + token2);
        // 使用基本的 Base64 编码器进行编码
        String svCiphertext = Base64.getEncoder().encodeToString(ss.getBytes());
        System.out.println("svCiphertext:" + svCiphertext);
        //获取当前时间的月和日
        String month = String.valueOf(java.time.LocalDate.now().getMonthValue());
        String day = String.valueOf(java.time.LocalDate.now().getDayOfMonth());
        //转成数字
        int monthNum = Integer.parseInt(month);
        int dayNum = Integer.parseInt(day);
        System.out.println("Month: " + month);
        System.out.println("dayNum: " + dayNum);
        StringBuilder builder = new StringBuilder(svCiphertext);
        builder.insert(monthNum - 1, token1);
        builder.insert(dayNum - 1, token2);
        svCiphertext = builder.toString();
        System.out.println("Encoded: " + svCiphertext);
        return svCiphertext;
    }

}
